﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace FieldServices
{
    public partial class frmWorkItem : UIFramework.UIForm
    {
        public frmWorkItem()
        {
            InitializeComponent();
            InitializeListItem();
        }
        private int OrderID;
        private DataTable dt = null;
        private void InitializeListItem()
        {
            //this.lstView.Items.Add(listViewItem6);
            this.lstView.Location = new System.Drawing.Point(3, 3);
            this.lstView.Name = "lstView";
            this.lstView.Size = new System.Drawing.Size(300, 262);
            this.lstView.TabIndex = 0;;
            this.lstView.View = System.Windows.Forms.View.Details;
            this.lstView.HeaderStyle = ColumnHeaderStyle.Nonclickable;

            ColumnHeader columnOrder = new ColumnHeader();
            columnOrder.Text = "Order";
            columnOrder.TextAlign = HorizontalAlignment.Left;
            columnOrder.Width = 100;

            ColumnHeader columnCustomer = new ColumnHeader();
            columnCustomer.Text = "Customer";
            columnCustomer.TextAlign = HorizontalAlignment.Center;
            columnCustomer.Width = 120;
            ColumnHeader columnStatus = new ColumnHeader();
            columnStatus.Text = "Status";
            columnStatus.TextAlign = HorizontalAlignment.Center;
            columnStatus.Width = 80;

            this.lstView.Columns.Add(columnOrder);
            this.lstView.Columns.Add(columnCustomer);
            this.lstView.Columns.Add(columnStatus);

            DataSet ds = Common.dsItems;
            dt = ds.Tables[0];
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                ListViewItem listItem = new ListViewItem(String.Format("{0} {1}", dt.Rows[i]["ORDERID"].ToString(), dt.Rows[i]["ORDER_TYPE"].ToString()));
                listItem.SubItems.Add(String.Format("{0} {1}", dt.Rows[i]["NAME"].ToString(), dt.Rows[i]["PARTNER"].ToString()));
                listItem.SubItems.Add(dt.Rows[i]["SYSTEM_STATUS"].ToString());
                lstView.Items.Add(listItem);
               
            }
            this.Controls.Add(lstView);
        }

        private void lst_view_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (lstView.SelectedIndices.Count == 0)
            return;
            int i = lstView.SelectedIndices.Count;
            string Order = String.Format("{0} {1}", dt.Rows[i]["ORDERID"].ToString(), dt.Rows[i]["ORDER_TYPE"].ToString());
            string Customer = String.Format("{0} {1}", dt.Rows[i]["NAME"].ToString(), dt.Rows[i]["PARTNER"].ToString());
            frmServicesOrder OrderDetail = new frmServicesOrder(Order, Customer);
            OrderDetail.Show();
        }

        private void btnNotification_Click(object sender, EventArgs e)
        {
            frmNotificationDetail frm = new frmNotificationDetail();
            frm.Show();
        }
    }
}